from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://www.baidu.com/")

driver.find_element(By.XPATH, "//input[@id='kw']").send_keys("python")
driver.find_element(By.XPATH, "//input[@id='su']").click()
time.sleep(2)

driver.find_element(By.XPATH, "//a[text()='(计算机编程语言) - 百度百科']").click()
time.sleep(2)

handers = driver.window_handles
print(handers)

driver.switch_to.window(handers[-1])
driver.find_element(By.XPATH, "//a[text()='首页']").click()
# driver.find_element(By.XPATH, "//a[text()=' 基础语法 | 菜鸟教程']").click()
time.sleep(5)

driver.quit()
